// 此文件用于路由拦截
import NProgress from 'nprogress'
import router from '@/router'
import store from '@/store'
import tools from '@/utils'
const whiteList = ['/login', '/testApp', '/forget', '/verification']
router.beforeEach((to, from, next) => {
  NProgress.start()
  const token = store.getters.token
  if (to.path === '/login') {
    tools.storage.removeToken()
  }
  if (token) {
    next()
  } else {
    if (whiteList.indexOf(to.path) > -1) {
      next()
    } else {
      next('/login')
    }
  }
  NProgress.done()
})
